//
//  DEWNewFriendCell.m
//  OtherDemo
//
//  Created by lianjie on 2018/7/25.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWNewFriendCell.h"
@interface DEWNewFriendCell ()
//
@property (nonatomic ,strong) UIImageView *headerImgV;
//
@property (nonatomic ,strong) UILabel *nameLab;
//
@property (nonatomic ,strong) UILabel *dateLab;
//
@property (nonatomic ,strong) UIButton *signBtn;

@end

@implementation DEWNewFriendCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
        
    }
    return self;
}

-(void)createView
{
    ///头像
    _headerImgV = [[UIImageView alloc]init];
//    _headerImgV.backgroundColor = CellLineColor;
    [self.contentView addSubview:_headerImgV];
    
    ///name
    _nameLab = [[UILabel alloc]init];
    [self.contentView addSubview:_nameLab];
    ///时间
    _dateLab = [[UILabel alloc]init];
    _dateLab.textColor = UIColorFromRGB(0xAAAAAA);
    _dateLab.font = [UIFont systemFontOfSize:11.0f];
    [self.contentView addSubview:_dateLab];
    
    ///关注按钮
    _signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_signBtn setTitleColor:UIColorFromRGB(0xFF8900) forState:UIControlStateNormal];
    _signBtn.layer.cornerRadius = 4.0f;
    _signBtn.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [_signBtn addTarget:self action:@selector(likeOtherPersonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_signBtn];
    
    [self setupViewFrame];
    
}

///设置frame
- (void)setupViewFrame
{
    CGFloat imgWH = 45.0f;
    _headerImgV.frame = CGRectMake(Margin_15, Margin_15, imgWH, imgWH);
    _headerImgV.layer.cornerRadius = imgWH/2;
    _headerImgV.layer.masksToBounds = YES;
    _headerImgV.layer.borderWidth = 1.0f;
    _headerImgV.layer.borderColor = CellLineColor.CGColor;
    
    ///name
    _nameLab.frame = CGRectMake(_headerImgV.right+Margin_15, Margin_15, 200, 23.0f);
    ///时间
    _dateLab.frame = CGRectMake(_nameLab.left, _nameLab.bottom+7.0f, _nameLab.width, 15.0f);
    ///关注按钮
    CGFloat btnW = 60.0f;
    CGFloat btnH = 25.0f;
    _signBtn.frame = CGRectMake(DEWScreenWidth-btnW-Margin_15, 25.0f, btnW, btnH);
    self.lj_lineWith = DEWScreenWidth-_nameLab.left;
}

///赋值
-(void)setFriendInfo:(NSMutableDictionary *)friendInfo
{
    ///头像
    [_headerImgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_URLIMAGE,friendInfo[@"avatarUri"]]] placeholderImage:kDefalutUserHeader];
    ///name
    NSString *name = [NSString stringWithFormat:@"%@",friendInfo[@"nickName"]];
    NSString *str01 = @"   关注了你";
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",name,str01]];
    [attStr setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16 weight:UIFontWeightHeavy],NSForegroundColorAttributeName:UIColorFromRGB(0x333333)} range:NSMakeRange(0, name.length)];
    
    [attStr setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:UIColorFromRGB(0x333333)} range:NSMakeRange(name.length, str01.length)];
    
    _nameLab.attributedText = attStr;
    
    //时间
    _dateLab.text = [DateHelper getTimeWithTimeIntervalString:[NSString stringWithFormat:@"%@",friendInfo[@"time"]]];
    ///按钮
    NSString *signStr = @"关注TA";
    
    NSInteger type = [[NSString FMAT:friendInfo[@"focusType"]] integerValue];
    
    /**
     0 未关注
     1 关注
     2 互相关注
     */
    if (type == 0) {
        signStr = @"关注TA";
        _signBtn.layer.borderColor = UIColorFromRGB(0xFF8900).CGColor;
        _signBtn.layer.borderWidth = 1.0f;
        _signBtn.layer.masksToBounds = YES;
    }else if (type == 1){
        signStr = @"互相关注";
    }else{
        signStr = @"互相关注";
    }
    [_signBtn setTitle:signStr forState:UIControlStateNormal];
    
}


#pragma mark ---关注
- (void)likeOtherPersonAction
{
    if (_delegate && [_delegate respondsToSelector:@selector(DEWNewFriendCellBackInfo:)]) {
        [_delegate DEWNewFriendCellBackInfo:self.indexPath];
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
